package com.hpdf.filter;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSONObject;
import com.hpdf.constants.ErrorType;
import com.hpdf.service.impl.DomeServiceImpl;
import com.hpdf.utils.exception.BizException;
import com.hpdf.utils.web.resultbean.BizResult;

/**
 * 方法增强.<br/>
 * 
 * Copyright: Copyright (c) 2017  zteits
 * 
 * @ClassName: MethodAdice.java
 * @Description: 
 * @version: v1.0.0
 * @author: wangfs
 * @date: 2017年7月24日   下午10:24:50 
 * Modification History:
 * Date             Author          Version            Description
 *---------------------------------------------------------*
 * 2017年7月24日      wangfs           v1.0.0               创建
 */
public class MethodAdice implements MethodInterceptor{
	private static final Logger logger = Logger.getLogger(MethodAdice.class);
	public Object invoke(MethodInvocation arg0) throws Throwable {
		BizResult result = new BizResult();
		logger.info("---begin调用业务层 "+arg0.getMethod().getName()+"()方法,入参="+JSONObject.toJSONString(arg0.getArguments()));
		Object obj =null;
		try{
			obj=arg0.proceed();//调用目标方法
		}catch (BizException e) {
			result.setErrCode(e.getErrCode());
			result.setErrMsg(e.getErrMsg());
		}
		catch (Exception e) {
			result.setErrCode(ErrorType.BIZ_ERROR.getCode());
			result.setErrMsg(ErrorType.BIZ_ERROR.getMsg());
		}
		logger.info("---end调用业务层"+arg0.getMethod().getName()+"()方法。");
		if(obj != null ){
			if(obj instanceof BizResult){
				result =(BizResult) obj;
			}
			
		}
		
		return result;
		
	}

}
